package com.zycx.system.role.controller;

import com.zycx.common.result.ServerResponse;
import com.zycx.system.role.entity.Role;
import com.zycx.system.role.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Description:
 * Created by zycx on 2018-12-11 20:38
 * Created with IntelliJ IDEA.
 */
@RestController
@RequestMapping("api/role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    /**
     * 添加角色
     *
     * @param role
     * @return
     */
    @PostMapping("")
    public ServerResponse saveRole(@RequestBody Role role) {
        return roleService.saveRole(role);
    }

    /**
     * 根据id 查询角色
     *
     * @param id id
     * @return role
     */
    @GetMapping("/{id}")
    public ServerResponse getRoleById(@PathVariable("id") String id) {
        return roleService.getRoleById(id);
    }

    /**
     * 根据id 修改角色
     *
     * @param role
     * @return
     */
    @PutMapping("/{id}")
    public ServerResponse putRole(@RequestBody Role role) {
        return roleService.putRole(role);
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public ServerResponse deleteRoleById(@PathVariable("id") String id) {
        return roleService.deleteRoleById(id);
    }


}
